package org.lucky.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.lucky.admin.mapper.InviteMapper;
import org.lucky.admin.service.IInviteService;
import org.lucky_common.domain.InviteParam;
import org.lucky_common.domain.LuckyShareCount;
import org.lucky_common.domain.User;
import org.lucky_common.vo.InviteExportVo;
import org.lucky_common.vo.UserExportVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@Service
public class InviteServiceImpl extends ServiceImpl<InviteMapper, InviteParam> implements IInviteService {

    @Resource
    private InviteMapper inviteMapper;

    @Override
    public List<InviteExportVo> getUserExportList() {
        List<InviteParam> users = this.list();
        //users集合转成export集合
        return users.stream().map(user -> {
            InviteExportVo vo = new InviteExportVo();
            BeanUtils.copyProperties(user, vo);
            return vo;
        }).collect(Collectors.toList());
    }

    @Override
    public Map<String, List> getCount() {
        List<LuckyShareCount> rolePermissionCount = inviteMapper.getCount();
        Map<String, List> longStringMap = new HashMap<>();
        List<Long> longs = new ArrayList<>();
        List<String> name = new ArrayList<>();
        name.add("完成的人数");
        longs.add((long) rolePermissionCount.size());
        List<LuckyShareCount> rolePermissionCount2 = inviteMapper.getCount2();
        name.add("未完成的人数");
        longs.add((long) rolePermissionCount2.size());

        longStringMap.put("count",longs);
        longStringMap.put("name",name);
        return longStringMap;
    }
}
